<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    // 最快
    const toogle = (n) => {
      if(n === 0) {
        return [0]
      }
      if(n === 1) {
        return [0, 1]
      }
      const result = toogle(n - 1)
      return [
        ...result,
        ...result.reverse().map(v => v + Math.pow(2, n - 1))
      ]
    }
    console.log(toogle(4));
    
  </script>
</body>
</html>